package com.xrath.rtm;

import java.io.Serializable;
import java.net.URL;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;

/**
 * Task object represents a task and task_series.
 * 
 * @author Jang-Ho Hwang, rath@xrath.com
 * @version 1.0, since 2008/06/01
 */
public class Task implements Serializable
{
	private TaskList list;
	private String id;
	private String seriesId;
	private String name;
	private URL url;
	private Date created;
	private Date modified;

	private Date due;
	private Date added;
	private Date completed;
	private Date deleted;

	private int priority; // 0-None, 1, 2, 3. change to Enum type?
	private String estimate; 
	private int postponed = 0;

	private List<String> tags;
	private List<Note> notes;
	private List<Contact> participants;

	/**
	 * Create a task.
	 */
	public Task()
	{
		this.tags = new ArrayList<String>(1);
		this.notes = new ArrayList<Note>(1);
		this.participants = new ArrayList<Contact>(1);
	}

	/**
	 * Create a task with given name.
	 */
	public Task( String name )
	{
		this();
		setName(name);
	}

	/**
	 * Set a TaskList object that include this task.
	 */
	public void setTaskList( TaskList list )
	{
		this.list = list;
	}

	/**
	 * Return the TaskList object that include this task.
	 */
	public TaskList getTaskList()
	{
		return this.list;
	}

	/** 
	 * Set the ID of this task.
	 */
	public void setId( String id )
	{
		this.id = id;
	}

	/**
	 * Return the ID of this task.
	 */
	public String getId()
	{
		return this.id;
	}

	/**
	 * Set the ID of task_series that include this task.
	 */
	public void setSeriesId( String id )
	{
		this.seriesId = id;
	}

	/**
	 * Return the ID of task_series that include this task.
	 */
	public String getSeriesId()
	{
		return this.seriesId;
	}

	/**
	 * Set the name of this task.
	 */
	public void setName( String name )
	{
		this.name = name;
	}

	/**
	 * Return the name of this task.
	 */
	public String getName()
	{
		return this.name;
	}

	/**
	 * Add a tag to this task. duplicated tag was automatically filtered 
	 * in this implementation. 
	 */
	public void addTag( String tag )
	{
		if( tags.contains(tag) )
			return;

		tags.add( tag );
	}

	/**
	 * Remove a tag with given name on this task. 
	 * It will not synchronize with the server. it only remove given tag on local.
	 */
	public void removeTag( String tag )
	{
		tags.remove( tag );
	}

	/**
	 * Returns tags of this task.
	 */
	public List<String> getTags()
	{
		return this.tags;
	}
	
	/**
	 * Add a note to this task.
	 */
	public void addNote( Note note )
	{
		if( notes.contains(note) )
			return;

		notes.add( note );
	}

	/**
	 * Remove given note on this task.
	 */
	public void removeNote( Note note )
	{
		notes.remove( note );
	}

	/**
	 * Return notes on this task.
	 */
	public List<Note> getNotes()
	{
		return this.notes;
	}

	/** 
	 * not implemented.
	 */
	public void addParticipant( Contact contact )
	{
		this.participants.add(contact);
	}

	/**
	 * not implemented.
	 */
	public void removeParticipant( Contact contact )
	{

	}

	/**
	 * not implemented.
	 */
	public List<Contact> getParticipants()
	{
		return this.participants;
	}

	/**
	 * Set the created date of this task_series.
	 */
	public void setCreated( Date created )
	{
		this.created = created;
	}

	/**
	 * Return the created date of this task_series.
	 */
	public Date getCreated()
	{
		return this.created;
	}

	/**
	 * Set the modified date of this task_series.
	 */
	public void setModified( Date modified )
	{
		this.modified = modified;
	}

	/**
	 * Return the modified date of this task_series.
	 */
	public Date getModified()
	{
		return this.modified;
	}

	/**
	 * Set the due-date of this task.
	 */
	public void setDue( Date due )
	{
		this.due = due;
	}

	/**
	 * Return the due-date of this task.
	 */
	public Date getDue()
	{
		return this.due;
	}

	/**
	 * Set the added date of this task.
	 */
	public void setAdded( Date added )
	{
		this.added = added;
	}

	/**
	 * Return the added date of this task.
	 */
	public Date getAdded()
	{
		return this.added;
	}

	/**
	 * Set the completed date of this task.
	 */
	public void setCompleted( Date completed )
	{
		this.completed = completed;
	}

	/**
	 * Return the completed date of this task.
	 */
	public Date getCompleted()
	{
		return this.completed;
	}

	/**
	 * Set the deleted date of this task.
	 */
	public void setDeleted( Date deleted )
	{
		this.deleted = deleted;
	}

	/**
	 * Return the deleted date of this task.
	 */
	public Date getDeleted()
	{
		return this.deleted;
	}

	/**
	 * Set the priority of this task.
	 *
	 * @param prior 1, 2, 3 or 0. zero value means that there is no priority.
	 */
	public void setPriority( int prior )
	{
		this.priority = prior;
	}

	/**
	 * Return the priority of this task.
	 *
	 * @return 1, 2, 3 or zero. zero value means that there is no priority.
	 */
	public int getPriority()
	{
		return this.priority;
	}

	/**
	 * Set the postponed count of this task.
	 */
	public void setPostponed( int count )
	{
		this.postponed = count;
	}

	/**
	 * Return the postponed count of this task. 
	 */
	public int getPostponed()
	{
		return this.postponed;
	}

	/**
	 * Set the time estimates of this task.
	 * 
	 * @param estimate time estimates of this task. '1 hr', '30 min', '1 hr 30 min'and '1.5 hrs' were available. See also <a href="http://www.rememberthemilk.com/help/answers/basics/timeestimateformat.rtm">http://www.rememberthemilk.com/help/answers/basics/timeestimateformat.rtm</a>.
	 */
	public void setEstimate( String estimate )
	{
		this.estimate = estimate;
	}

	/**
	 * Return the time estimates of this task.
	 *
	 * @return time estimates of this task. '1 hr', '30 min', '1 hr 30 min'and '1.5 hrs' were available. See also <a href="http://www.rememberthemilk.com/help/answers/basics/timeestimateformat.rtm">http://www.rememberthemilk.com/help/answers/basics/timeestimateformat.rtm</a>.
	 */
	public String getEstimate()
	{
		return this.estimate;
	}

	/**
	 * Set the related URL of this task.
	 */
	public void setURL( URL url )
	{
		this.url = url;
	}

	/**
	 * Return the related URL of this task.
	 */
	public URL getURL()
	{
		return this.url;
	}
}

